<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        body {
            padding: 100px;
        }
        
        textarea {
            width: 200px;
            height: 100px;
            border: 1px solid pink;
            outline: none;
            resize: none;
        }
        
        ul {
            margin-top: 50px;
        }
        
        li {
            width: 300px;
            padding: 5px;
            background-color: rgb(245, 209, 243);
            color: red;
            font-size: 14px;
            margin: 15px 0;
        }
        
        li a {
            float: right;
        }
    </style>
</head>

<body>
    <textarea name="" id="text"></textarea>
    <button>发布</button>
    <ul>

    </ul>
</body>

<script>
    let textHtml = document.querySelector('#text');
    let but = document.querySelector('button');
    let ul = document.querySelector('ul');
    console.log(textHtml);
    but.onclick = function() {
        console.log(textHtml.value);
        if (textHtml.value == '') {
            alert('请输入有效字符后再发布！！！');
        } else {
            //alert(textHtml.value);
            let addUl = document.querySelector('ul');
            let li = document.createElement('li');
            li.innerHTML = textHtml.value + '<a href="javascript:;s">删除</a>';
            ul.appendChild(li);
            textHtml.value = '';
            let a = li.querySelector('a');
            a.onclick = function() {
                ul.removeChild(this.parentNode);
            }
        }
    }
</script>

</html>